// 设备ID
var moduleId = getQueryString('id');
var moduleType = getQueryString('moduleType');
var deviceId = '';
$(function () {
    var queryUrl = '../ermsfile/list';
    if (moduleId) {
        queryUrl += '?moduleId=' + moduleId + '&moduleType=' + moduleType;
    }
    $("#jqGrid").Grid({
        url: queryUrl,
        multiselect: false,
        colModel: [
            {name: 'fileTypeId', hidden: true},
            {label: '资料类别', name: 'fileTypeName', index: 'FILE_TYPE_NAME', sortable: false},
            {label: '资料数', name: 'fileNum', index: 'FILE_TYPE_NAME', width: 60, sortable: false},
            {
                label: '附件', width: 60, align: 'center', sortable: false,
                formatter: function (value, col, row) {
                    return "<button class='btn btn-outline btn-info' onclick='vm.goEquFile(\"" + row.fileTypeId + "\")'><i class='fa fa-list-ol'></i>&nbsp;查看</button>";
                }
            },
            {
                label: '操作', width: 60, align: 'center', sortable: false,
                formatter: function (value, col, row) {
                    return "<button class='btn btn-outline btn-info' onclick='vm.know(\"" + row.fileTypeId + "\")'><i class='fa fa-upload'></i>&nbsp;纳入知识库</button>";
                }
            }
        ]
    });
});

var vm = new Vue({
    el: '#rrapp',
    data: {
        fileTypeList: [],
        fileType: '',
    },
    methods: {
        getFileTypeList: function () {
            let queryRrl = "../filetype/queryAll";
            if (type) {
                queryRrl += "?type=" + type;
            }
            Ajax.request({
                url: queryRrl,
                type: "POST",
                successCallback: function (r) {
                    vm.fileTypeList = r.list;
                }
            });
        },
        // 纳入知识库
        know: function (devEquFileId) {
            openWindow({
                type: 2,
                title: '<i class="fa fa-upload"></i> 请选择要纳入的知识库',
                content: '../sys/knowbase.html',
                btn: ['确定', '取消'],
                btn1: function (index) {
                    var iframeWin = window["layui-layer-iframe" + index];
                    var knowbaseId = iframeWin.getKnowbaseId();
                    if (!knowbaseId) {
                        iview.Message.error("请选择一条记录");
                    } else {
                        var param = {moduleId: moduleId, fileTypeId: devEquFileId, knowbaseId: knowbaseId,moduleType: moduleType};
                        Ajax.request({
                            url: "../ermsfile/saveKnow",
                            params: JSON.stringify(param),
                            type: "POST",
                            contentType: "application/json",
                            successCallback: function (r) {
                                alert('操作成功', function (index) {
                                    vm.reload();
                                });
                            }
                        });
                        layer.close(index);
                    }
                }
            })
        },
        query: function () {
            vm.reload();
        },
        reload: function (event) {
            vm.showList = true;
            var page = $("#jqGrid").jqGrid('getGridParam', 'page');
            $("#jqGrid").jqGrid('setGridParam', {
                postData: {},
                page: page
            }).trigger("reloadGrid");
        },
        goEquFile: function (fileTypeId) {
            openWindow({
                type: 2,
                title: '<i class="fa fa-list-ul"></i> 附件列表',
                content: '../sys/equFile.html?fileTypeId=' + fileTypeId + '&moduleType=' + moduleType + '&moduleId=' + moduleId,
                cancel: function (index) {
                    layer.close(index);
                    vm.reload();
                }
            })
        }
    }
});